
foo.mod['scroll_table_bdy'] = {

	init: function(scrollableTables){
		
		// setTimeout is to give the sortable table plugin some time to work first.
		// setTimeout should be converted to an existence of 'sortable' + polling approach.
		// only apply to ie8, safari, chrome, and opera
		if(/safari|opera|chrome|ie8/.test($('html').attr('class'))){
			
			setTimeout(function(){
				
				foo.log("foo.mod['scroll_table_bdy'].init()");
				
				scrollableTables.each(function() {
					
					// safari needs the table width set explicitly.
					if($('html.safari').size()) {
						$('table',this).css('width', this.offsetWidth - ($('html.safari3').size()?15:17));
					}
					
					// opera needs the table width set explicitly.
					if($('html.opera').size()) {
						$('table',this).css('width', this.offsetWidth - 18);
					}
					
					// chrome needs the table width set explicitly.
					if($('html.chrome').size()) {
						$('table',this).css('width', this.offsetWidth - 18);
					}
					
					var original = this;
					
					// create the duplicate table head
					var duplicateTable = $(this).clone(false).addClass('duplicate').insertAfter(this);
					
					$(this).addClass('original');//.find('thead tr').add(duplicateTable.find('tbody tr')).css('display','none');
					
					// transfer klik to original
					var ths = $('thead th',duplicateTable).klik(function(){
						var dupeTH = this;
						var twin = $('thead th', original).eq( ths.index(this) ).click();
						setTimeout(function(){
							// remove classnames from sibling duplicate THs.
							ths.removeClass('headerSortUp headerSortDown');
							// set classnames to same as original.
							$(dupeTH).attr('class', twin.attr('class'));
						}, 50);
					});
					
				});
					
			}, 300);
		}
	}

};